package com.atguigu.transform;

import org.apache.flink.streaming.api.datastream.ConnectedStreams;
import org.apache.flink.streaming.api.datastream.DataStreamSource;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;
import org.apache.flink.streaming.api.functions.co.CoMapFunction;

import java.util.HashMap;

/**
 * 1.	两个流中存储的数据类型可以不同
 * 2.	只是机械的合并在一起, 内部仍然是分离的2个流
 * 3.	只能2个流进行connect, 不能有第3个参与
 * @author wky
 * @create 2021-07-14-9:29
 */
public class Transform_Connect {
    public static void main(String[] args) throws Exception {
        StreamExecutionEnvironment senv = StreamExecutionEnvironment.getExecutionEnvironment();
        DataStreamSource<Integer> streamSource1 = senv.fromElements(1, 2, 3, 4, 5, 6);
        DataStreamSource<String> streamSource2 = senv.fromElements("a", "b", "c", "d");
        ConnectedStreams<Integer, String> connect = streamSource1.connect(streamSource2);
        HashMap<Integer, String> map = new HashMap<>();
        connect.map(new CoMapFunction<Integer, String, String>() {
            Integer a = null;
            String  b = null;
            @Override
            public String map1(Integer integer) throws Exception {
                a = integer;
                return integer+"";
            }

            @Override
            public String map2(String s) throws Exception {
                b = s ;
                return s;
            }


        }).print();
        senv.execute();


    }

}
